#ifndef _LOOPINFO_H_
#define _LOOPINFO_H_

#include <llvm/ADT/APSInt.h>
#include <llvm/Support/raw_ostream.h>
#include <clang/Rewrite/Rewriter.h>
#include <clang/AST/Stmt.h>
#include "SubscriptExpr.h"

/** Struct containing information about one loop induction variable. */
struct InductionVarInfo {
    std::string name;
    llvm::APSInt lbound;
    llvm::APSInt ubound;
    llvm::APSInt step; // currently not used: assume 1

};

/** A class for storing all information about a loop. */
class LoopNestInfo : public std::vector<InductionVarInfo> {

    clang::Rewriter rewriter;
    clang::FileID mainFileID;
    std::vector<clang::SourceLocation> stmtLocs;
    std::vector<clang::Stmt*> statements;
    
public:
    std::vector<SubscriptExpr> reads;
    std::vector<SubscriptExpr> writes;

    // search for the index of a variable by name.
    //  since we are assuming only one variable, this won't be used.
    int getIndex(std::string varname);

    /** Add a statement reference to the loop info */
    void addStmt(clang::Stmt* stmt);
    
    void addStmtLoc(clang::SourceLocation loc);

    void setRewriter(clang::Rewriter rw, clang::FileID fid);
        
    void insertStatementComment(int stmtIndex, std::string comment); 

    void replaceStmt(int oldstmt, int newstmt); 

    int nStatements(); 

    // access methods for the bounds of the outermost induction variable.
    llvm::APSInt lbound();
    llvm::APSInt ubound();

    void writeSource(llvm::raw_ostream* outfile);

    // size() is inherited from vector.
    
};

#endif
